import { utilJs } from '@/utils/common.js'
const apiArr = [
  'api/company/bindPhoneInstall', // non-wechat
  'api/giftCard/getGiftCardBaseInfo', // non-wechat
  'api/social/getMsgFilterList', // non-wechat
  'api/social/inviteList', // non-wechat
  'api/sendRed/checkUserAuth', // non-wechat
  'api/company/share', // non-wechat
  // 'api/mp/authCallback',
  'api/social/cacheWatchTime', // non-wechat
  'api/common/newUserOP', // non-wechat
  'api/common/getBottomNav' // non-wechat
  /*
  'api/common/visitStat',
  'api/social/addSocialRoom',
  'api/mp/initAuth', */
];

// 商家先去掉'lj7l',
const hpCompanyArr = [
  '8rxm',
  'm8rmjd',
  '36oe8v',
  'jz2z',
  'b92pwa',
  'dx2gbv',
  '89xwxr',
  'b9kxwa',
  'ww6xbd',
  'jzq8p8',
  'exp3j3',
  'expkaa',
  'p3a6q9',
  'rbmd6r',
  'qmavae',
  'va56kv',
  '36ozab',
  'm8rmew',
  'kjrgek',
  '897zr3',
  '79jzyd',
  'jz59ge',
  'g9byk8',
  'a92jjd',
  'expooa',
  'a92jbo',
  'rbm582',
  'jz59bg',
  'zkzwov',
  'qmav7e',
  'wwvo2r',
  '286z2b',
  'x9vq3p',
  'rbm5zq',
  'p3a588',
  'p3arkk',
  '79jee7',
  'dxxyjb',
  'qma32a',
  'm8rmjd',
  'pey6',
  'exp8jw',
  // , 'g99zdq'
  '28yb2d',
  '36ooeb',
  'wwvqod',
  'b9kyda',
  // 'lj7l'
];

// 需要个别商家添加个别接口
const apiArr2 = ['api/mp/jsConfig'];
const hpCompanyArr2 = [
  'zkzwov',
  'rbm5zq',
  'wwvo2r',
  '897zr3',
  'ww6krk',
  'kjrgek',
  'qmav7e',
  'm8rmew',
  'exp3j3',
  'x9v273',
  // , '79jzyd', 'p3arkk'
  // before 202308:
  'b9kddw',
  '79jee7',
  'dxxyjb',
  'qma32a',
  'm8rmjd',
  'pey6',
  'exp8jw',
  // , 'g99zdq'
  '28yb2d',
  '36ooeb',
  'wwvqod',
  'b9kyda'
];

//所有商家都走apihp的接口
const apiArr3 = ['api/comment/list', 'api/comment/commentTemplate', 'api/comment/submit', 'api/analyse/userTraceLog'];
//所有多门店商家的share接口都不走apihp
const noApihpArr = ['api/company/share'];

function checkApiHp(url) {
  let companyId = utilJs.getCompanyIdByHerf();
  let eurl = url;
  //一些普通接口走apihp的商家
  if (hpCompanyArr.includes(companyId)) {
    for (let i = 0;i < apiArr.length;i++) {
      if (url.includes(apiArr[i])) {
        eurl = url.replace('/api/', '/apihp/');
        break;
      }
    }
  }
  //jsconfig接口走apihp的商家
  if (hpCompanyArr2.includes(companyId)) {
    for (let i = 0;i < apiArr2.length;i++) {
      if (url.includes(apiArr2[i])) {
        eurl = url.replace('/api/', '/apihp/');
        break;
      }
    }
  }
  //所有商家都走apihp的接口
  for (let i = 0; i < apiArr3.length; i++) {
    if (url.includes(apiArr3[i])) {
      eurl = url.replace('/api/', '/apihp/');
      break;
    }
  }

  //多门店的部分接口不走apihp
  if (utilJs.getStoreId()) {
    for (let i = 0; i < noApihpArr.length; i++) {
      if (url.includes(noApihpArr[i])) {
         eurl = url.replace('/apihp/', '/api/');
        break;
      }
    }
  }

  return eurl;
}

export { checkApiHp };
